package com.roger.cmdkit.demo;

public class SynchronizedTest implements Runnable{

    private static int i = 0;

    public static void main(String[] arg) throws InterruptedException {
        Thread t1 = new Thread(new SynchronizedTest());
        Thread t2 = new Thread(new SynchronizedTest());
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(i);
    }

    @Override
    public void run() {
        for(int j=0;j<100;j++) {
            synchronized(this) {
                i++;
            }
        }
    }
}
